import 'dart:io';

import 'package:dio/dio.dart';
import 'package:fsharing/core/services/auth.dart';
import 'package:fsharing/core/viewmodels/view_model.dart';

class UserAvatarUpdateModel extends ViewModel {
  final Auth auth;
  File file;
  String _errorMessage;

  UserAvatarUpdateModel(this.auth) : super();

  String get errorMessage => _errorMessage;

  Future<ViewState> userAvatarUpdate() async {
    viewState = ViewState.busy;
    try {
      await auth.userAvatarUpdate(file);
      viewState = ViewState.success;
    } catch (e) {
      _errorMessage = e is DioError ? e.message : e.toString();
      viewState = ViewState.error;
    }
    return viewState;
  }
}
